<?php

namespace App\Criteria;

use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;

/**
 * Class DatatableCriteriaCriteria.
 *
 * @package namespace App\Criteria;
 */
class DatatableSearchCriteriaCriteria implements CriteriaInterface
{
    /**
     * Apply criteria in query repository
     *
     * @param string              $model
     * @param RepositoryInterface $repository
     *
     * @return mixed
     */
    public function apply($model, RepositoryInterface $repository)
    {
        // 搜索框中的值
        $search['value'] = request('search.value', '');

        if ($search['value']) {
            $model = $model->where('name', 'like', "%{$search['value']}%")->orWhere('guard_name','like', "%{$search['value']}%");
            
        }

        return $model;
    }
}
